package org.lyimg.com.imgapplication.activity;

import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;

import org.lyimg.com.imgapplication.R;
import org.lyimg.com.imgapplication.adapter.ImgDetailRecAdapter;
import org.lyimg.com.imgapplication.bean.ImgInfo;
import org.lyimg.com.imgapplication.presenter.ImgShowPresenter;
import org.lyimg.com.imgapplication.utils.SpacesItemDecoration;
import org.lyimg.com.imgapplication.view.IimgShowView;
import java.util.List;

public class ImgShowActivity extends BaseActivity<IimgShowView,ImgShowPresenter> implements IimgShowView {

    RecyclerView show_recycler;
    String link;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_img_show);
        Toolbar toolbar =  findViewById(R.id.toolbar_show);
        setSupportActionBar(toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        show_recycler =  findViewById(R.id.show_recycler);
        //设置布局管理器
        show_recycler.setLayoutManager(new LinearLayoutManager(this));
        //设置Item增加、移除动画
        show_recycler.setItemAnimator(new DefaultItemAnimator());
        SpacesItemDecoration decoration = new SpacesItemDecoration(10);
        show_recycler.addItemDecoration(decoration);

        link  = getIntent().getStringExtra("link");

        presenter.setUrl(link);
        presenter.getImgs();
    }

    @Override
    protected ImgShowPresenter creatPresenter() {
        return  new ImgShowPresenter();
    }

    @Override
    public void showLoadingDialog() {
        showDialog();
    }

    @Override
    public void dissLoadingDialog() {
        dismissDialog();
    }

    @Override
    public void showMsgToast(String msg) {

    }

    @Override
    public void showImgList(List<ImgInfo> imgs) {
        show_recycler.setAdapter(new ImgDetailRecAdapter(ImgShowActivity.this, imgs));
    }
}
